package com.lfs.market.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lfs.market.model.entity.Orders;
import com.lfs.market.model.vo.StatCategoryVo;
import com.lfs.market.model.vo.StatMonthlyDealVo;
import com.lfs.market.model.vo.StatSaleVo;
import com.lfs.market.model.vo.StatWeeklyDealVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * 操作orders相关数据接口
 */
public interface OrdersMapper extends BaseMapper<Orders> {

    /**
     * 标记未支付的订单状态为删除
     *
     * @return
     */
    @Select("SELECT * FROM orders WHERE create_time < NOW() - INTERVAL 5 MINUTE and status = 2")
    List<Orders> orderTaskDelete();

    List<StatSaleVo> selectStatSale();

    @Select("SELECT COUNT(*) FROM orders WHERE DATE(create_time) = DATE(#{today})")
    Integer getDailyOrderCount(@Param("today") String today);

    @Select("SELECT SUM(total_price) FROM orders WHERE DATE(create_time) = #{today}")
    BigDecimal getTodaySales(String today);

    @Select("SELECT COUNT(*) FROM orders WHERE YEAR(create_time) = YEAR(CURDATE()) AND MONTH(create_time) = MONTH(CURDATE())")
    Integer getThisMonthOrderCount();

    @Select("SELECT SUM(total_price) FROM orders WHERE YEAR(create_time) = YEAR(CURDATE()) AND MONTH(create_time) = MONTH(CURDATE())")
    BigDecimal getThisMonthSales();

    @Select("SELECT type_name as name, COUNT(*) AS value FROM product_info WHERE status = 9 GROUP BY type_name;")
    List<StatCategoryVo> getCategoryData();

    List<StatMonthlyDealVo> getMonthlyDeal(@Param("year") Integer year);

    List<StatWeeklyDealVo> getWeeklyDeal();

    /**
     //      * 新增
     //    */
//    int insert(Orders orders);
//
//    /**
//      * 删除
//    */
//    int deleteById(Integer id);
//
//    /**
//      * 修改
//    */
//    int updateById(Orders orders);
//
//    /**
//      * 根据ID查询
//    */
//    Orders selectById(Integer id);
//
//    /**
//      * 查询所有
//    */
//    List<Orders> selectAll(Orders orders);
//
//    @Select("select * from orders where order_no = #{orderNo}")
//    Orders selectByOrderNo(String orderNo);
}